package org.paradise.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.paradise.dao.PackageDao;
import org.paradise.dao.PacktypeDao;
import org.paradise.dao.VipDao;
import org.paradise.dao.VipTypeDao;
import org.paradise.pojo.Package;
import org.paradise.pojo.PackageType;
import org.paradise.pojo.Vip;
import org.paradise.pojo.VipType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/viptype")
public class ViptypeController {
    @Autowired
    private VipTypeDao vipTypeDao;
    @Autowired
    private VipDao vipDao;
    @Autowired
    private PacktypeDao packtypeDao;
    @Autowired
    private PackageDao packageDao;
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit)throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<VipType> pager= PageHelper.startPage(page,limit);
        List<VipType> list=vipTypeDao.getAll();
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        map.put("count",pager.getTotal());
        return  map;
    }
    @RequestMapping("/updatecard")
    @ResponseBody
    public Map<String,Object> updatecard(VipType vipType) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipTypeDao.update(vipType);
        return map;
    }
    @RequestMapping("/addcard")
    @ResponseBody
    public Map<String,Object> addcard(VipType vipType) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipTypeDao.add(vipType);
        return map;
    }
    @RequestMapping("/delid")
    @ResponseBody
    public Map<String,Object> delid(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipTypeDao.delete(id);
        return map;
    }
    @RequestMapping("/getzi")
    @ResponseBody
    public  Map<String,Object> deletezi(Integer id)throws  Exception {
        Map<String, Object> map = new HashMap<>();
        List<Vip> list = vipDao.getzi(id);
        if (list.size() > 0) {
            map.put("code", 1);
            return map;
        }
        map.put("code", 0);
        return map;
    }
    @RequestMapping("/getAll")
    @ResponseBody
    public List<PackageType> getAll() throws Exception{
        return packtypeDao.getAll();
    }
    @RequestMapping("/getRole")
    @ResponseBody
    public VipType getByUserName(String name,Integer id) throws Exception{
        return vipTypeDao.getrole(name,id);
    }
    @RequestMapping("/dangeid")
    @ResponseBody
    public Map<String,Object> dangeid(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        List<Package> list=packageDao.getaaa(id);
//        if(aPackage != null){
//            list.add(aPackage);
//        }
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        return  map;
    }
    @RequestMapping("/packagename")
    @ResponseBody
    public PackageType packagename(String name) throws Exception{
        return packtypeDao.getpackagetypename(name);
    }
}
